<template>
	<view class="container">
		<template v-if="empty">
		    <view class="tabsContent">
				<u-empty mode="data" width="280" height="280" textSize="28"
		     icon="http://cdn.uviewui.com/uview/empty/data.png" text="您未填写反馈信息"></u-empty>
		    </view>
		</template>
		<template v-else>
			<view class="feedback-box" v-for="(item,index) in feedbackList" >
				<view class="feedback-left" @click="toFeedbackDetails(item)">
					<!-- 标题title -->
					<view class="feedback-title">{{item.title}}</view>
					<view class="feedback-time">{{item.creatTime}}</view>
				</view>
				<view class="feedback-right">
					<u-button type="primary" size="mini" :plain="true" text="编辑" @click="updateFeedback(item)"></u-button>
					<u-button type="error" style="margin-left: 10rpx;" size="mini" :plain="true" text="删除" @click="delFeedback(item,index)"></u-button>
				</view>
			</view>
		</template>
		<view style="width:100% ;height:110rpx ;">
			
		</view>
		<view class="bottomBtn">
			<u-button @click="addFeedback()" type="primary" text="添加反馈信息"></u-button>
		</view>
		<u-modal :show="deleteShow" :title="deleteTitle" showCancelButton buttonReverse :zoom="false"
			:closeOnClickOverlay="true" @confirm="deleteConfirm" @cancel="deleteShow = false"
			@close="deleteShow = false "></u-modal>
	</view>
</template>

<script>
	import api from '@/api/api.js';
	export default {
		name: '',
		components: {},
		data() {
			return {
				pageNum:1,
				pageSize:10,
				feedbackList:[],
				num:null,//条数
				empty:false,//是否为空
				deleteShow: false,
				deleteTitle: '是否确认删除',
				deleteId: null,
			}
		},
		onShow(){
			const _that=this
			_that.pageNum=1
			_that.feedbackList=[]
			_that.num=null
			_that.deleteShow=false
			_that.empty=false
			this.getFeedbackList();
		},
		created() {
			
		},
		mounted() {},
		destroyed() {},
		methods: {
			// 获取意见反馈列表
			getFeedbackList(type){
				let userInfo = uni.getStorageSync('userInfo')
				let data={
					pageNum:this.pageNum,
					pageSize:this.pageSize,
					userId: userInfo.id
				}
				api.getFeedback(data).then(res=>{
					if(res.data.code==601){
						this.empty=true
					}else if(res.data.code==200){
						this.feedbackList=this.feedbackList.concat(res.data.rows)
						this.num=Math.ceil(res.data.total/this.pageSize)//总条数除一页多少条向上取整
						this.pageNum++
					}
				})
			},
			// 新增意见反馈
			addFeedback(){
				uni.$u.route('/pages/feedback/addFeedback');
			},
			// 编辑意见反馈
			updateFeedback(item){
				uni.$u.route({
					type:"navigateTo",
					url: "/pages/feedback/addFeedback",
					params: {
						id: item.id
					}
				});
			},
			// 删除意见反馈
			delFeedback(item,index){
				this.deleteShow = true;
				this.deleteTitle = `是否确认删除 反馈标题为`+item.title
				this.deleteId = item.id
			},
			deleteConfirm() {
				this.deleteShow = false;
				api.delFeedback(this.deleteId).then(res => {
					if (res.data.code == 200) {
						this.pageNum=1
						this.feedbackList=[]
						this.num=null
						this.getFeedbackList()
						setTimeout(() => {
							uni.$u.toast('删除成功')
						}, 300)
					}
				}).catch(err => {
					uni.$u.toast(err.msg)
				})
			},
			// 跳转意见反馈详情页
			toFeedbackDetails(item){
				uni.$u.route({
					type:"navigateTo",
					url: "/pages/feedback/details",
					params: {
						id: item.id
					}
				});
			}
		},
		onReachBottom() {
			// 触底的时候请求数据，即为上拉加载更多
			if(this.pageNum<=this.num){
				this.getFeedbackList()
			}
		},
		// 下拉刷新
		onPullDownRefresh() {
			const _that=this
			_that.pageNum=1
			_that.feedbackList=[]
			_that.num=null
			_that.empty=false
			_that.deleteShow=false
			setTimeout(function () {
				uni.stopPullDownRefresh();
				_that.getFeedbackList();
			}, 500);
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		width: calc(100% - 32rpx);
		padding: 16rpx;
		.tabsContent {
			width: 100%;
			background-color: #FFFFFF;
			height: 1000rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}
		.feedback-box{
			background-color: #fff;
			width: 95%;
			border-radius: 20rpx;
			padding: 20rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 20rpx;
			.feedback-left{
				width: 85%;
				.feedback-title{
					font-size: 32rpx;
					font-weight: bold;
					white-space:nowrap;
					overflow:hidden;
					text-overflow:ellipsis;
				}
				.feedback-time{
					font-size: 20rpx;
					color: #666;
					margin-top: 20rpx;
				}
			}
			.feedback-right{
				display: flex;
				align-items: center;
				font-size: 24rpx;
				color: #666;
			}
		}
		.bottomBtn{
			position: fixed;
			width: calc(100% - 63rpx) ;
			padding: 32rpx;
			bottom: 0;
			left: 0;
			background-color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
			box-shadow: 0rpx 1rpx 8rpx 0rpx #e5e5e5;
		}
	}
</style>
